package com.rran.study.designpattern.structural.flyweight;

import java.util.HashMap;

/**
 * @author yy
 * @Type ColorFactory.java
 * @Desc 享元工厂
 * @date 2020/7/24 20:26
 */
public class ColorFactory {
    private static final HashMap<String, Brush> map = new HashMap<>();

    public static Brush getBrush(String color) {
        Board board = (Board) map.get(color);
        if (board == null) {
            board = new Board(color);
            map.put(color, board);
            System.out.println("创建颜色为 : " + color + "的棋子");
        }else{
            System.out.println("复用颜色为 : " + color + "的棋子");
        }
        return board;
    }
}
